package com.orm.analysis.dao.impl;

import com.orm.analysis.dao.GenericJPADAO;
import com.orm.analysis.model.Address;
import com.orm.analysis.model.InternationalAddress;
import com.orm.analysis.model.InternationalAddress;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Query;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: saman
 * Date: 10/18/13
 * Time: 12:09 AM
 * To change this template use File | Settings | File Templates.
 */
public class InterAddressDAO  extends GenericJPADAO<InternationalAddress, Integer> {

    /**
           *
           *
           * @param page the page number
           * @param size the page size
           * @return a list of InternationalAddress
           */
          public List<InternationalAddress> list(int page, int size) {
              Query query = this.em.createQuery("select a  from InternationalAddress a");
              query.setFirstResult((page - 1) * size);
              query.setMaxResults(size);
              return query.getResultList();
          }


          public InternationalAddress getById(Integer id) {
                  return this.em.find(InternationalAddress.class,id);
          }

          @Transactional
          @Override
          public void save(InternationalAddress entity) {
               getEntityManager().persist(entity);
          }

       @Transactional
       @Override
       public void saveList(List<InternationalAddress> entities) {
           for(Address entity: entities){
               getEntityManager().persist(entity);
           }

       }


    @Transactional
                @Override
                    public void delete(Object id) {
                        getEntityManager().remove(getEntityManager().find(InternationalAddress.class, id));

                     }


}
